﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Objects;
using System.Linq;
using System.Text;

namespace WebAuto.DataModel
{
    public class Data
    {
        private IntTesterEntities6 _intTesterEntities;
        public Data()
        {
            if (CanDoDatabaseStuff())
            {
                _intTesterEntities = new IntTesterEntities6();
            }
        }

        public bool CanDoDatabaseStuff()
        {

            return ConfigurationManager.AppSettings["HasDataBase"].ToLower() == "true";

        }


        public void SaveTestRun(string testName, string testFileName, string testFileLocation, DateTime runDate, string runStatus, string message,string resultFolderLocation,string browser)
        {
            if (CanDoDatabaseStuff())
            {

                _intTesterEntities.pr_SaveTestRun(testName, testFileName, testFileLocation, runDate, runStatus, message, resultFolderLocation, browser);
            }

        }

        public ObjectResult<pr_GetTestRunStatusCount_Result> GetTestRunStatusCount(string testName)
        {
            if (CanDoDatabaseStuff())
            {
                return _intTesterEntities.pr_GetTestRunStatusCount(testName);

            }
            return null;
        }

        public List<pr_GetTestRunStatusCount_Chart_Result> GetTestRunStatusCount_Chart(string testName)
        {
            if (CanDoDatabaseStuff())
            {
                return _intTesterEntities.pr_GetTestRunStatusCount_Chart(testName).ToList();

            }
            return null;
        }

        public List<pr_GetTestRunDetailsPerNameAndStatus_Result> GetTestRunDetailsPerNameAndStatus(string testName, string runStatus)
        {
            if (CanDoDatabaseStuff())
            {
                return _intTesterEntities.pr_GetTestRunDetailsPerNameAndStatus(testName, runStatus).ToList();

            }
            return null;
        }


    }
}
